package course.p4_list.s2_TwoNextList;

import course.p4_list.List;

public class DLinkedList implements List {

    /**
     * 头节点
     */
    Node head;
    /**
     * 链表大小
     */
    int size;
    /**
     * 尾节点
     */
    Node tail;


    @Override
    public int calSize() {
        int length = 0;
        Node currentNode = head;
        while (currentNode!=null) {
            length++;
            currentNode = currentNode.next;
        }
        size = length;
        return length;
    }

    @Override
    public int size() {
        return size;
    }

    public String toString() {
        Node currentNode = head;
        if(currentNode == null) {
            return "null";
        }
        StringBuilder stringBuilder = new StringBuilder();
        for(;;){
            stringBuilder.append(currentNode.nodeName);
            currentNode = currentNode.next;
            if(currentNode == null){
                break;
            }else {
                stringBuilder.append("<->");
            }
        }
        return stringBuilder.toString();
    }

    @Override
    public void insert(int element, int position) {

    }

    @Override
    public void add(int element) {

    }

    public void addFirst(int element){

    }

    @Override
    public int remove(int position) {
        return 0;
    }

    @Override
    public void removeFirst(int element) {

    }

    public void removeLast(int element){

    }

    @Override
    public void update(int element, int position) {

    }

    @Override
    public int get(int position) {
        return 0;
    }

}
